package com.li.controller;

import com.li.pojo.Require;
import com.li.pojo.Zhibiao;
import com.li.service.ZhibiaoService;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.annotation.Resource;
import java.util.Collection;

@Controller
public class ZhibiaoController {

    @Resource
    ZhibiaoService service;


    @RequestMapping("/zhibiaos")
    public String list(Model model){
        Collection<Zhibiao> zhibiaos=service.allZhibiao();
        model.addAttribute("zhibiaos",zhibiaos);
        return "zhibiao/list";
    }
    @GetMapping(value = "/tozhibiao")
    public String tozhibiao(Model model){

        return "zhibiao/add";
    }
    @RequestMapping(value = "/zhibiao/add")
    //@ResponseBody
    public String addZhibiao(Zhibiao zhibiao){
        if(service.addZhibiao(zhibiao))return "redirect:/zhibiaos";
        return "序号重复，添加失败";
    }
    @RequestMapping(value = "/zhibiao/query")
    public String queryZhibiao(){
        return "";
    }

    @GetMapping("/zhibiao/{ind}")
    public String toupdateZhibiao(
            @PathVariable("ind")String ind, Model model){
        Zhibiao zhibiao=new Zhibiao(ind);
        zhibiao=service.queryZhibiao(zhibiao);
        model.addAttribute("zhi",zhibiao);
        //Collection<Class> classes=studentService.allClass();
        // model.addAttribute("classes",classes);
        return "zhibiao/update";
    }
    @RequestMapping(value = "/zhibiao/update")
    public String updateZhibiao(Zhibiao zhibiao){
        System.out.println("1");
        service.updateZhibiao(zhibiao);
        return "redirect:/zhibiaos";
    }
    @RequestMapping(value = "/delezhibiao/{ind}")
    public String deleteZhibiao(@PathVariable("ind")String ind){
        Zhibiao zhibiao=new Zhibiao(ind);
        service.deleteZhibiao(zhibiao);
        return "redirect:/zhibiaos";
    }
}
